/**
 * @param {number} m
 * @param {number} n
 * @return {number}
 */
var uniquePaths = function (m, n) {
    const memo = new Array(m).fill(0).map(() => new Array(n).fill(-1))
    function dfs(i, j) {
        if (i < 0 || j < 0) {
            return 0
        }
        if (i === 0 && j === 0) {
            return 1
        }
        if (memo[i][j] !== -1) {
            return memo[i][j]
        }
        memo[i][j] = dfs(i - 1, j) + dfs(i, j - 1)
        return memo[i][j]
    }
    return dfs(m - 1, n - 1)
};